/*include:js\mathJax\load*/
var ExamLog = {
Load:function()
	{
	this.Types=[{}];
	this.Types.push({Function:this.SetLoad});
	this.Types.push({Function:this.GetQuestion,Timeout:100});
	this.Types.push({Function:this.ShowAnswer});
	this.Types.push({Function:this.SetRadioAnswer,Timeout:500*2});
	this.Types.push({Function:this.SetMultipleAnswer,Timeout:500*2});
	this.Types.push({Function:this.SetQuestion,Timeout:2000*2});
	this.Types.push({Function:this.StopPlay});

	var SkinValue=fastCSharp.PageView.SkinValue,Exam=SkinValue.exam.Remote;
	this.Questions=Exam.RadioDescriptionQuestions.GetArray().concat(Exam.MultipleChoiceDescriptionQuestions.GetArray()).concat(Exam.QuestionDescriptionQuestions.GetArray());

	this.Logs=SkinValue.SkinValue.logs;
	this.Logs.push({Times:-1,IntType:2,Index:1});
	this.Logs=this.Logs.sort(function(Left,Right){return Left.Times-Right.Times;});
	this.Logs[0].Times=0;
	this.Logs.push({Times:this.MaxPlayTime=this.Logs[this.Logs.length-1].Times,IntType:this.Types.length-1});
	this.PlayIndexs=[];
	SkinValue.PlayLoadTimer.Set({LoadLeft:0});
	var PlayLoadPoints=[],PlayLoadWidth=fastCSharp.$Id('playLoad').Width();
	for(var Time=SkinValue.SkinValue.exam.MaxMinutes*60*1000,Index=0,LoadPoint=0,QuestionIndex;Index-this.Logs.length;++Index)
		{
		var Log=this.Logs[Index];
		if(!(Log.IsAnswer=Log.Index>0))	Log.Index=-Log.Index;
		--Log.Index;
		if(Log.IntType==1)	LoadPoint=Log.LoadPoint=Log.Index;
		else if(Log.IntType==2)
			{
			Log.LoadPoint=LoadPoint;
			QuestionIndex=Log.Index;
			PlayLoadPoints.push({Index:this.PlayIndexs.length,LoadLeft:Math.floor(Log.Times*(PlayLoadWidth-20)/this.MaxPlayTime+10),Question:this.Questions[QuestionIndex].SkinValue});
			this.PlayIndexs.push(Index);
			}
		Log.PlayLoadTimer={LoadLeft:Log.Times*(PlayLoadWidth-20)/this.MaxPlayTime+10};
		var Seconds=Math.floor((Time-Log.Times)/1000);
		Log.Timer={Hours:Math.floor(Seconds/(60*60)),Minutes:Math.floor((Seconds/60)%60),Seconds:Math.floor(Seconds%60)};
		Log.QuestionIndex=QuestionIndex;
		Log.Question=this.Questions[QuestionIndex];
		Log.Type=this.Types[Log.IntType];
		Log.PlayFunction=fastCSharp.ThisFunction(this,Log.Type.Function,[Log]);
		}
	SkinValue.PlayLoadPoints.Set(PlayLoadPoints);
	SkinValue.IsStopPlay.Set(0);
	this.CurrentQuestionIndex=-1;
	this.SetLoad({LoadPoint:0});
	this.LogIndex=0;
	this.PlayNext();
	},
SetPlayLoadMenu:function(Event,Menu)
	{
	var Element=fastCSharp.$Id('playLoad'),XY=Element.XY();
	Event.clientY=XY.Top+Element.Height();
	var Time=this.MaxPlayTime*Math.min(Math.max((Event.clientX-XY.Left-10)/(Element.Width()-20),0),1);
	for(var Index=this.PlayIndexs.length;Index;)
		{
		var Log=this.Logs[this.PlayIndexs[--Index]];
		if(Time>=Log.Times)	break;
		}
	var Log=this.Logs[this.PlayMenuIndex=this.PlayIndexs[Index]],Seconds=Math.floor(Time/1000);
	Menu.SkinView.Timer={Hours:Math.floor(Seconds/(60*60)),Minutes:Math.floor((Seconds/60)%60),Seconds:Math.floor(Seconds%60)};
	Menu.SkinView.Question=Log.Question.SkinValue;
	fastCSharp.Skins.playLoadMenu.Show(Menu.SkinView);
	},
SetPlayLoad:function()
	{
	clearInterval(this.PlayInterval);
	this.LogIndex=this.PlayMenuIndex;
	fastCSharp.PageView.SkinValue.IsStopPlay.Set(0);
	this.PlayNext();
	},
SetPlayPoint:function(Index)
	{
	clearInterval(this.PlayInterval);
	this.LogIndex=this.PlayIndexs[Index];
	fastCSharp.PageView.SkinValue.IsStopPlay.Set(0);
	this.PlayNext();
	},
PausePlay:function(IsPause)
	{
	if(IsPause)
		{
		fastCSharp.PageView.SkinValue.SkinValue.IsPausePlay=1;
		fastCSharp.PageView.SkinValue.IsStopPlay.Set(0);
		clearInterval(this.PlayInterval);
		}
	else if(this.Logs.length-this.LogIndex)
		{
		fastCSharp.PageView.SkinValue.SkinValue.IsPausePlay=0;
		fastCSharp.PageView.SkinValue.IsStopPlay.Set(0);
		this.PlayNext();
		}
	},
StopPlay:function()
	{
	clearInterval(this.PlayInterval);
	fastCSharp.PageView.SkinValue.PlayLoadTimer.Set({LoadLeft:0});
	this.LogIndex=0;
	fastCSharp.PageView.SkinValue.SkinValue.IsPausePlay=0;
	fastCSharp.PageView.SkinValue.IsStopPlay.Set(1);
	},
PlayNext:function()
	{
	var Log=this.Logs[this.LogIndex++];
	if(this.Logs.length-this.LogIndex)
		{
		if(!fastCSharp.PageView.SkinValue.SkinValue.IsPausePlay)	this.PlayInterval=setTimeout(fastCSharp.ThisFunction(this,this.PlayNext),Log.Type.Timeout||0);
		}
	Log.PlayFunction();
	},
SetLoad:function(Log)
	{
	var SkinValue=fastCSharp.PageView.SkinValue;
	fastCSharp.PageView.SkinValue.userExam.Set(new diantou.userExam({Exam:SkinValue.SkinValue.exam,AnswerPoint:Log.LoadPoint}));
	},
SetTimer:function(Log)
	{
	fastCSharp.PageView.SkinValue.PlayLoadTimer.Set(Log.PlayLoadTimer);
	fastCSharp.PageView.SkinValue.Timer.Set(Log.Timer);
	},
GetQuestion:function(Log)
	{
	this.SetLoad(Log);
	this.SetTimer(Log);
	if(this.CurrentQuestionIndex!=-1)	this.Questions[this.CurrentQuestionIndex].IsCurrent.Set(0);
	this.Questions[this.CurrentQuestionIndex=Log.QuestionIndex].IsCurrent.Set(1);
	fastCSharp.Skins.question.Show(Log.Question.SkinValue);
	},
ShowAnswer:function(Log)
	{
	fastCSharp.PageView.SkinValue.Timer.Set(Log.Timer);
	var Question=Log.Question.SkinValue;
	switch(Question.Type)
		{
		case 'Radio':
			Question.RadioAnswers()[Log.Index].IsAnswer=1;
			Log.Question.Set();
			break;
		case 'MultipleChoice':
			var QuestionAnswers=Question.MultipleAnswers();
			for(var Answers=eval('['+Log.Content+']'),AnswerIndex=Answers.length;AnswerIndex;QuestionAnswers[Answers[--AnswerIndex]].IsAnswer=1);
			Log.Question.Set();
			break;
		case 'Question':
			MentionEditor.GetHtmlEditor({Element:fastCSharp.$Id('questionAnswer')}).SetHtml(Log.Content);
			break;
		}
	},
SetRadioAnswer:function(Log)
	{
	this.SetTimer(Log);
	for(var Answers=Log.Question.SkinValue.RadioAnswers(),Index=Answers.length;Index;)
		{
		var Answer=Answers[--Index];
		Answer.IsAnswer=Answer.Index==Log.Index;
		}
	fastCSharp.Skins.question.Show(Log.Question.SkinValue);
	},
SetMultipleAnswer:function(Log)
	{
	this.SetTimer(Log);
	Log.Question.SkinValue.MultipleAnswers()[Log.Index].IsAnswer=Log.IsAnswer;
	fastCSharp.Skins.question.Show(Log.Question.SkinValue);
	},
SetQuestion:function(Log)
	{
	this.SetTimer(Log);
	MentionEditor.GetHtmlEditor({Element:fastCSharp.$Id('questionAnswer')}).SetHtml(Log.Content);
	}
		};
fastCSharp.OnLoad(ExamLog.Load,ExamLog,1);